package com.xyazm.order.mq.consumer;


import com.alibaba.fastjson.JSONObject;
import com.xyazm.common.constants.RocketMqConstant;
import com.xyazm.order.service.IAfterSaleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单支付超时自动关单 2.0
 * @author xuyou
 * @date 2023年02月23日 22:11
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = RocketMqConstant.ORDER_PAY_TIMEOUT_DELAY_TOPIC,
        consumerGroup = RocketMqConstant.ORDER_PAY_TIMEOUT_CONSUMER_GROUP,
        selectorExpression = "*",
        consumeMode = ConsumeMode.CONCURRENTLY,
        messageModel = MessageModel.CLUSTERING,
        consumeThreadMax = 1
)
public class OrderPayTimeoutListener extends AbstractRocketMqListener {

    @Autowired
    private IAfterSaleService afterSaleService;


    @Override
    public void onMessage(String message) {
        JSONObject object = JSONObject.parseObject(message);
        String orderId = object.getString("orderId");
        //  执行取消订单前验证
        afterSaleService.verifyBeforeOrderCancellation(orderId);
    }
}
